

package com.dog.basics.service.sys.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dog.basics.bean.dto.admin.sys.AdminSysLogFromDto;
import com.dog.basics.bean.model.sys.SysLog;
import com.dog.basics.bean.vo.admin.sys.AdminSysLogVo;
import com.dog.basics.common.util.PageParam;
import com.dog.basics.dao.sys.SysLogMapper;
import com.dog.basics.service.sys.SysLogService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 日志表 服务实现类
 * </p>
 *
 * @author guonh
 * @since 2017-11-20
 */
@Service
public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> implements SysLogService {
    /**
     * @Description: 分页系统日志
     * @Param: status
     * @return: IPage<项目Vo>
     * @Author: wph
     * @Date:
     */
    @Override
    public IPage<AdminSysLogVo> getPageList(PageParam page, AdminSysLogFromDto obj) {

        IPage iPage = this.page(page, Wrappers.<SysLog>lambdaQuery()

                .like(StrUtil.isNotBlank(obj.getOperation()), SysLog::getOperation, obj.getOperation())
                .like(StrUtil.isNotBlank(obj.getUsername()), SysLog::getUsername, obj.getUsername())
                .between(ObjectUtil.isNotNull(obj.getStartTime()) && ObjectUtil.isNotNull(obj.getEndTime()), SysLog::getCreateDate, obj.getStartTime(), obj.getEndTime())
                .orderBy(Boolean.TRUE, obj.getIsOrderByAvg(), SysLog::getCreateDate));
        List<SysLog> records = iPage.getRecords();
        iPage.setRecords(records.stream().map(e -> {
            AdminSysLogVo newsVo = new AdminSysLogVo();
            BeanUtil.copyProperties(e, newsVo);
            return newsVo;
        }).collect(Collectors.toList()));
        return iPage;
    }

}
